from rules.peaces.AbstractPeace import AbstractPeace;
from core import Utils;
from core import PlayerColor;
from core.PeacePosition import PeacePosition;
from core import PeaceType;

class WhitePawn(AbstractPeace):

    def __init__(self, controller, type):
        AbstractPeace.__init__(self, controller, type);

    def checkMotion(self, sP, fP):
        dX = sP.x - fP.x;
        dY = sP.y - fP.y;
        targetCell = self._controller.boardData.getPeaceByCell(fP);
        targetCellIsClear = targetCell == PeaceType.BLANK_CELL;
        nextCellIsClear = self._controller.boardData.getPeaceByCell(PeacePosition(sP.x, sP.y - 1)) == PeaceType.BLANK_CELL;
        targetCellIsEnemy = Utils.getPeaceColor(targetCell) == PlayerColor.BLACK;
        checkMotionForward = nextCellIsClear and targetCellIsClear and dX == 0 and (dY == 1 or (dY == 2 and sP.y == 7));
        checkTraverseMotion = targetCellIsEnemy and abs(dX) == 1 and dY == 1;
        if(checkMotionForward or checkTraverseMotion):
            return True;
        else:
            return False;